package blog.action;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.github.pagehelper.PageInfo;
import blog.entity.Article;
import blog.entity.Comment;
import blog.entity.Link;
import blog.entity.Notice;
import blog.enums.ArticleStatus;
import blog.enums.LinkStatus;
import blog.enums.NoticeStatus;
import blog.service.ArticleService;
import blog.service.CommentService;
import blog.service.LinkService;
import blog.service.NoticeService;

@Controller
public class IndexAction {

	//文章信息
    @Resource
    private ArticleService articleService;
    	
	//评论信息
	@Resource
	private CommentService commentService;
	
	//友情链接
	@Resource
	private LinkService linkService;
	
	//公告
	@Resource
	private NoticeService noticeService;
	

    @RequestMapping(value = {"/", "/article"})
    public String index(@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
                        @RequestParam(required = false, defaultValue = "10") Integer pageSize, ModelMap  m) {

        HashMap<String, Object> paramMap = new HashMap<>(1);
        paramMap.put("status", ArticleStatus.PUBLISH.getValue());
        
        //文章列表
        PageInfo<Article> articleList = articleService.getPageArticleList(pageIndex, pageSize, paramMap);
        m.put("pageInfo", articleList);
        m.put("pageUrlPrefix", "/article?pageIndex");
        
           
        //最新评论
        List<Comment> recentCommentList = commentService.listRecentComment(10);
        m.put("recentCommentList",recentCommentList);
        
        //友情链接(在framework.jsp中做的显示)
        List<Link> linkList = linkService.listLink(LinkStatus.NORMAL.getValue());
        m.put("linkList", linkList);
    
        //公告 
        List<Notice> noticeList = noticeService.listNotice(NoticeStatus.NORMAL.getValue());
        m.put("noticeList", noticeList);
        
         return "index"; 
    }

}

